/**
 * 
 */
package com.moji.cyg.biz.user;

import java.util.HashMap;
import java.util.Map;

import com.moji.cyg.common.condition.Precondition;
import com.moji.cyg.common.security.SecurityUtil;

/**
 * @author shengli.caosl 2012-2-25 下午2:34:49
 */
public class UserServiceImpl implements UserService {

    private UserDAO userDAO;

    /**
     * @param userDAO the userDAO to set
     */
    public void setUserDAO(UserDAO userDAO) {
        this.userDAO = userDAO;
    }

    @Override
    public boolean createUser(UserModel userModel) {
        Precondition.checkNotNull(userModel, "User can not null!");
        userModel.setStatus(UserEnumSet.USER_STATE.ENABLE.toString());
        userModel.setVersion(0);
        userModel.setPassword(SecurityUtil.getEncryptWord(userModel.getPassword()));
        return userDAO.createUser(userModel) > 0;
    }

    /*
     * (non-Javadoc)
     * @see com.moji.cyg.biz.user.UserService#getUserByNameAndPassword(java.lang.String, java.lang.String)
     */
    @Override
    public UserModel getUserByNameAndPassword(String userName, String password) {
        Map<String, Object> parameter = new HashMap<String, Object>(4, 1);
        parameter.put("userName", userName);
        parameter.put("password", SecurityUtil.getEncryptWord(password));
        return userDAO.getUserByNameAndOther(parameter);
    }
}
